package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;

import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import org.come.mouslisten.ChoseSmallLookMouslisten;
import org.come.mouslisten.SEPMouslisten;

import com.tool.tcpimg.RichLabel;
import com.tool.tcpimg.UIUtils;

public class SmallExpressionJpanel extends JPanel{
	
	private JLabel[] labSmallLooks = new JLabel[40];//放置小表情
	private ChoseSmallLookMouslisten[] choseSmallLookMouslistens = new ChoseSmallLookMouslisten[40]; //表情监听
	private static int index = 1;//判断表情是在第几页
	public static ImageIcon icon;
	public SmallExpressionJpanel() throws Exception {
		
	this.setPreferredSize(new Dimension(504, 348));
	this.setLayout(null);
	this.setBackground(UIUtils.Color_BACK);
	this.setOpaque(false);
	//放置小表情
	for (int i = 0; i < 40; i++) {
		int row = i%8;
		int col = i/8;
		labSmallLooks[i] = new JLabel();
		labSmallLooks[i].setBounds(5+60*row+row*2, 5+60*col+col*2, 60, 60);
		labSmallLooks[i].setBackground(new Color(0,0,0,0));
		choseSmallLookMouslistens[i] = new ChoseSmallLookMouslisten(i);
		labSmallLooks[i].addMouseListener(choseSmallLookMouslistens[i]);
		this.add(labSmallLooks[i]);
	}
	ImageIcon icon=new ImageIcon("skin/8100226/button/B162.png");
	Font font=new Font("宋体", 1, 14);
	for (int i = 0; i < 5; i++) {
		JLabel yb=new JLabel();
		yb.setBounds(10+i*48, 318, 41, 25);
		yb.setIcon(icon);
		yb.setBackground(new Color(0,0,0,0));
		yb.setText((i+1)+"");
		yb.setForeground(Color.WHITE);
		yb.setHorizontalTextPosition(SwingConstants.CENTER);
		yb.setFont(font);
		SEPMouslisten sepMouslisten=new SEPMouslisten(this, i+1);
		yb.addMouseListener(sepMouslisten);
		this.add(yb);
	}		
	}
	private RichLabel[] bqs;
	
	public RichLabel[] getbqs(){
		if (bqs==null) {
            bqs=new RichLabel[40];
        }
		for (int i = 0; i < 40; i++) {
			int xs=(index-1)*40+i;
			if (xs<168) {	
				if (bqs[i]!=null) {
					bqs[i].setText("#"+xs);					
				}else {
					bqs[i]=new RichLabel("#"+xs, UIUtils.TEXT_FONT);	
				}
			}else {
				if (bqs[i]!=null) {
                    bqs[i].setText("");
                }
			}
				
		}	
		return bqs;
    }
	@Override
    protected void paintComponent(Graphics g) {
    	// TODO Auto-generated method stub
		 if (SmallExpressionJpanel.icon == null) {
	            SmallExpressionJpanel.icon = new ImageIcon("inkImg/old/background/S145.png");
	        }

	        g.drawImage(SmallExpressionJpanel.icon.getImage(), 0, 0, 482, 348, this);
	        	        
    	super.paintComponent(g);
    	if (bqs==null) {
            getbqs();
        }
    	for (int i = 0; i < bqs.length; i++) {
			if (bqs[i]!=null) {
				int row = i%8;
				int col = i/8;
				if (!"".equals(bqs[i].getText())) {
					Graphics g2 = g.create(8+60*row, 8+60*col, 100, 100);
					
					bqs[i].paint(g2);
					
					g2.dispose();	
				}
				
			}
		}
    }
	public JLabel[] getLabSmallLooks() {
		return labSmallLooks;
	}

	public void setLabSmallLooks(JLabel[] labSmallLooks) {
		this.labSmallLooks = labSmallLooks;
	}

	public ChoseSmallLookMouslisten[] getChoseSmallLookMouslistens() {
		return choseSmallLookMouslistens;
	}

	public void setChoseSmallLookMouslistens(
			ChoseSmallLookMouslisten[] choseSmallLookMouslistens) {
		this.choseSmallLookMouslistens = choseSmallLookMouslistens;
	}

	public static int getIndex() {
		return index;
	}

	public static void setIndex(int index) {
		SmallExpressionJpanel.index = index;
	}

}
